package com.example.voting_master.common.api;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * ClassName: Result
 * Package: com.studays.common
 * Description:
 *
 * @Author JYC
 * @Create 2023/9/1 11:25
 * @Version 1.0
 */
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private Integer code; //编码：1成功，0和其它数字为失败

    private String msg; //错误信息

    private T data; //数据

    private Map map = new HashMap(); //动态数据

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Map getMap() {
        return map;
    }

    public void setMap(Map map) {
        this.map = map;
    }

    public static <T> Result<T> success(T object,String msg) {
        Result<T> r = new Result<T>();
        r.setData(object);
        r.setCode(1);
        r.setMsg(msg);
        return r;
    }

    public static <T> Result<T> error(String msg) {
        Result<T> r = new Result<T>();
        r.setMsg(msg);
        r.setCode(0);
        return r;
    }

    public static <T> Result<T> error(int errcode, String msg) {
        Result<T> r = new Result<T>();
        r.setMsg(msg);
        r.setCode(errcode);
        return r;
    }
}
